{% extends "base.html" %}

{% block content %}
<div class="row">
    <!-- 左侧学科分类 -->
    <div class="col-md-3">
        <!-- 学科分类 -->
        <div class="card">
            <div class="card-header">学科分类</div>
            <div class="list-group list-group-flush">
                <a href="#" class="list-group-item list-group-item-action" data-subject="语文">语文</a>
                <a href="#" class="list-group-item list-group-item-action" data-subject="数学">数学</a>
                <a href="#" class="list-group-item list-group-item-action" data-subject="英语">英语</a>
                <a href="#" class="list-group-item list-group-item-action" data-subject="科学">科学</a>
                <a href="#" class="list-group-item list-group-item-action" data-subject="思品">思品</a>
                <a href="#" class="list-group-item list-group-item-action" data-subject="信息">信息</a>
                <a href="#" class="list-group-item list-group-item-action" data-subject="写字">写字</a>
                <a href="#" class="list-group-item list-group-item-action" data-subject="美术">美术</a>
                <a href="#" class="list-group-item list-group-item-action" data-subject="音乐">音乐</a>
                <a href="#" class="list-group-item list-group-item-action" data-subject="校本">校本</a>
                <a href="#" class="list-group-item list-group-item-action" data-subject="党建">党建</a>
                <a href="#" class="list-group-item list-group-item-action" data-subject="德育">德育</a>
                <a href="#" class="list-group-item list-group-item-action" data-subject="教务">教务</a>
                <a href="#" class="list-group-item list-group-item-action" data-subject="其他">其他</a>
            </div>
        </div>
    </div>

    <!-- 右侧文件列表 -->
    <div class="col-md-9">
        <!-- 筛选条件 -->
        <div class="card mb-3">
            <div class="card-body">
                <div class="row align-items-end">
                    <!-- 年份筛选 -->
                    <div class="col-md-3">
                        <label for="yearFilter" class="form-label">年份筛选</label>
                        <select class="form-select" id="yearFilter">
                            <option value="all">全部年份</option>
                            {% for year in years %}
                            <option value="{{ year.year }}">{{ year.year }}年</option>
                            {% endfor %}
                        </select>
                    </div>
                    
                    <!-- 年级筛选 -->
                    <div class="col-md-3">
                        <label for="gradeFilter" class="form-label">年级筛选</label>
                        <select class="form-select" id="gradeFilter">
                            <option value="all">全部年级</option>
                            <option value="一年级">一年级</option>
                            <option value="二年级">二年级</option>
                            <option value="三年级">三年级</option>
                            <option value="四年级">四年级</option>
                            <option value="五年级">五年级</option>
                            <option value="六年级">六年级</option>
                            <option value="全体">全体</option>
                        </select>
                    </div>
                    
                    <!-- 上传按钮 -->
                    <div class="col-md-3">
                        <button type="button" class="btn btn-primary w-100" data-bs-toggle="modal" data-bs-target="#uploadModal">
                            上传文件
                        </button>
                    </div>
                </div>
            </div>
        </div>

        <!-- 文件列表 -->
        <div class="card">
            <div class="card-header">我的文件</div>
            <div class="card-body">
                <div class="table-responsive">
                    <table class="table">
                        <thead>
                            <tr>
                                <th>文件名</th>
                                <th>上传者</th>
                                <th>学科</th>
                                <th>年级</th>
                                <th>年份</th>
                                <th>描述</th>
                                <th>上传时间</th>
                                <th>可见性</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            {% for file in files %}
                            <tr>
                                <td>{{ file.original_filename }}</td>
                                <td>{{ file.owner.real_name }}</td>
                                <td>{{ file.subject }}</td>
                                <td>{{ file.grade }}</td>
                                <td>{{ file.school_year.year }}年</td>
                                <td>{{ file.description }}</td>
                                <td>{{ file.upload_time.strftime('%Y-%m-%d %H:%M:%S') }}</td>
                                <td>
                                    {% if file.is_public %}
                                    <span class="badge bg-success">全员可见</span>
                                    {% else %}
                                    <span class="badge bg-secondary">私有</span>
                                    {% endif %}
                                </td>
                                <td>
                                    <a href="{{ url_for('download_file', file_id=file.id) }}" class="btn btn-sm btn-primary">下载</a>
                                </td>
                            </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 上传文件模态框 -->
<div class="modal fade" id="uploadModal" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">上传文件</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>
            <div class="modal-body">
                <form action="{{ url_for('upload_file') }}" method="POST" enctype="multipart/form-data">
                    <div class="mb-3">
                        <label for="file" class="form-label">选择文件</label>
                        <input type="file" class="form-control" id="file" name="file" required>
                    </div>
                    <div class="mb-3">
                        <label for="subject" class="form-label">选择学科</label>
                        <select class="form-select" id="subject" name="subject" required>
                            <option value="语文">语文</option>
                            <option value="数学">数学</option>
                            <option value="英语">英语</option>
                            <option value="科学">科学</option>
                            <option value="思品">思品</option>
                            <option value="信息">信息</option>
                            <option value="写字">写字</option>
                            <option value="美术">美术</option>
                            <option value="音乐">音乐</option>
                            <option value="校本">校本</option>
                            <option value="党建">党建</option>
                            <option value="德育">德育</option>
                            <option value="教务">教务</option>
                            <option value="其他">其他</option>
                        </select>
                    </div>
                    <div class="mb-3">
                        <label for="grade" class="form-label">选择年级</label>
                        <select class="form-select" id="grade" name="grade" required>
                            <option value="">请选择年级</option>
                            <option value="一年级">一年级</option>
                            <option value="二年级">二年级</option>
                            <option value="三年级">三年级</option>
                            <option value="四年级">四年级</option>
                            <option value="五年级">五年级</option>
                            <option value="六年级">六年级</option>
                            <option value="全体">全体</option>
                        </select>
                    </div>
                    <div class="mb-3">
                        <label for="year" class="form-label">选择年份</label>
                        <select class="form-select" id="year" name="year" required>
                            <option value="">请选择年份</option>
                            {% for year in years %}
                            {% if year.is_active %}
                            <option value="{{ year.id }}">{{ year.year }}年</option>
                            {% endif %}
                            {% endfor %}
                        </select>
                    </div>
                    <div class="mb-3">
                        <label for="description" class="form-label">文件描述</label>
                        <textarea class="form-control" id="description" name="description" rows="3"></textarea>
                    </div>
                    <div class="mb-3 form-check">
                        <input type="checkbox" class="form-check-input" id="is_public" name="is_public" checked>
                        <label class="form-check-label" for="is_public">全员可见</label>
                    </div>
                    <button type="submit" class="btn btn-primary">上传</button>
                </form>
            </div>
        </div>
    </div>
</div>
{% endblock %} 